<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        ul{
            width: 500px;
            height: 300px;
            background-image: url("e.png");
            background-size: 100% 100%;
            border: 1px solid #000; 
            margin: 100px auto;
        }
        li {
            width: 100px;
        }

        .action {
            background-image: linear-gradient(rgba(255, 0, 0, 0), rgba(23, 22, 22, 0.647) 120%);
        }
    </style>
</head>
<body>
    <div></div>
    <ul></ul>
    <script>
        var str = "", str1 = "";
        for (let i = 1; i < 9; i++) {
          str += `<audio src="./notes/${i}.oga"></audio>`;
          str1 += "<li></li>"
        }
        var div = document.querySelector("div");
        var ul = document.querySelector("ul");
        div.innerHTML = str;
        ul.innerHTML = str1;
        var as = document.querySelectorAll("audio");
        var lis = document.querySelectorAll("li");
        for (let m = 0; m < lis.length; m++) {
            lis[m].onmousedown = function () {
                as[m].load();
                as[m].play();
                this.classList.add("action");
            }
            lis[m].onmouseup = function () {
                this.classList.remove("action");
            }
        }
        window.onkeydown = function (e) {
            if (e.keyCode >= 49 && e.keyCode <= 57) {
                var m = e.keyCode - 49;
                as[m].load();
                as[m].play();
                lis[m].classList.add("action");
            }
        }
        window.onkeyup = function (e) {
            if (e.keyCode >= 49 && e.keyCode <= 57) {
                var m = e.keyCode - 49;
                lis[m].classList.remove("action");
            }
        }
    </script>
</body>
</html>   